package com.heima.article.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ArticleHomeService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
public class ArticleClient implements IArticleClient {

    @Autowired
    private ArticleHomeService articleHomeService;
    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {
        return articleHomeService.saveArticle(dto);
    }
    /**
     * 判断文章是否可以评论
     * @param articleId
     * @return
     */
    @GetMapping("/api/v1/article/isComment")
    public ResponseResult  isComment(@RequestParam("articleId") Long articleId){

        LambdaQueryWrapper<ApArticleConfig> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ApArticleConfig::getArticleId,articleId);
        ApArticleConfig apArticleConfig = apArticleConfigService.getOne(lqw);

        return ResponseResult.okResult(apArticleConfig);
    }
}
